package com.xingdata.jjxc.adapter;

import java.util.List;

import android.content.Context;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.xingdata.jjxc.R;
import com.xingdata.jjxc.activity.CommentListView;
import com.xingdata.jjxc.enty.CommentListEntity;
import com.xingdata.jjxc.utils.JUtils;
import com.xingdata.jjxc.views.CircleImageView;

/**
 * 评论列表格式
 * 
 * @author ysc
 * 
 */
public class CommentAdapter extends BaseAdapter {
	private Context context;
	private LayoutInflater inflater;
	private List<CommentListEntity> listEntities;
	private CommentListEntity commentListEntity;

	public CommentAdapter(Context context2, List<CommentListEntity> listEntities, CommentListView commentActivity) {
		this.context = context2;
		this.listEntities = listEntities;
	}

	@Override
	public int getCount() {
		return listEntities == null ? 0 : listEntities.size();
	}

	@Override
	public CommentListEntity getItem(int position) {
		return listEntities.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(R.layout.commentwindow, null);
			holder.CommentHeadSculpture = (CircleImageView) convertView.findViewById(R.id.CommentHeadSculpture);
			holder.CommentNickName = (TextView) convertView.findViewById(R.id.CommentNickName);
			holder.CommentTime = (TextView) convertView.findViewById(R.id.CommentTime);
			holder.Comment_tv = (TextView) convertView.findViewById(R.id.Comment_tv);
			// 设置字体
			Typeface font = Typeface.createFromAsset(context.getAssets(), JUtils.TypefacePath);
			holder.CommentNickName.setTypeface(font);
			holder.CommentTime.setTypeface(font);
			holder.Comment_tv.setTypeface(font);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		commentListEntity = listEntities.get(position);
		holder.CommentHeadSculpture.setImageResource(R.drawable.add_bus_car);

		holder.CommentNickName.setText(commentListEntity.getUser_name());
		holder.CommentTime.setText(commentListEntity.getComment_ctime());
		holder.Comment_tv.setText(commentListEntity.getComment_text());
		return convertView;
	}

	final class ViewHolder {
		private TextView CommentNickName, CommentTime, Comment_tv;
		private CircleImageView CommentHeadSculpture;
	}
}
